// pages/index/business/detail/index.js
import { jpzzList, enterpriseService, titleStyle } from "../../../../utils/data/tabbar";
import {yuanqu} from "../../../../utils/api/module/yuanqu.js"
import {getgetUnion} from "../../../../utils/api/module/cylm.js"
import {getZzList} from "../../../../utils/api/module/task.js"
Page({
    data: {
        gbConfig: getApp().globalData.config,
        currentData: ['/assets/img/banner01.png'],
        showFlag: true,
        enterpriseService,
        jpzzList: [], //租赁信息
        titleStyle, // 标题
        detailInfo: '',
        mapIcon:true
    },
    onLoad: function (options) {
        // this.getZzList();
        if(!options.datatype) {
            this.getInfo(options.id);
            return false;
        };
        if(options.datatype) {
            this.data.datatype = options.datatype;
            this.getgetUnion(options.id);
            return false;
        };
    },
    // 招租信息
    getZzList: function() {
        getZzList({
            limit: 6,
            isrec: 1
        }).then(res => {
            this.setData({
                jpzzList: res.data.data
            })
        })
    },
    // 联盟成员
    getgetUnion: function(id) {
        getgetUnion({id: id}).then(res => {
            let data = res.data.data;
            data.coordinates = data.coordinates.split(',');
            let mapMks = [
                {
                    latitude: data.coordinates[0],
                    longitude:data.coordinates[1],
                    iconPath: "/assets/img/local09.png",
                    width: 24,
                    height: 26,
                    label:{
                        anchorX: 0,
                        anchorY: -60,
                        content: data.address,
                        color:"#000000",
                        fontSize:14,
                        padding: 6,
                        borderRadius: 4,
                        textAlign:'center',
                        bgColor: "#ffffff",
                        borderColor:"#aaaaaa"
                    }

                }
            ]
            this.setData({
                datatypeData: res.data.data,
                datatype: this.data.datatype,
                mapMks:mapMks
            })
            let self = this;
            wx.createSelectorQuery().select('.lf-detail-synopsis').boundingClientRect(function (rect) {
                let height = rect.height
                console.log(rect.height)
                self.setData({
                    showFlag: height < 110 ? false : true
                })
            }).exec()
        })
    },
    bindDown: function() {
        this.setData({
            showFlag: false
        })
    },
    go: function(e) {
        let url = e.currentTarget.dataset.url;
        wx.navigateTo({
          url: url,
        })
    },
    /**
     * 获取园区详情
     * @param id
     */
    getInfo(id){
        yuanqu({
            "id": id,
        }).then(res => {
            // 处理地图标记点
            let itude= res.data.data.coordinates.split(",");
            let llItude={
                long:itude[1],
                lat: itude[0]
            }
            let mapMks = [
                {
                    latitude:itude[0],
                    longitude:itude[1],
                    iconPath: "/assets/img/local09.png",
                    width: 24,
                    height: 26,
                    label:{
                        anchorX: 0,
                        anchorY: -60,
                        content: res.data.data.address,
                        color:"#000000",
                        fontSize:14,
                        padding: 6,
                        borderRadius: 4,
                        textAlign:'center',
                        bgColor: "#ffffff",
                        borderColor:"#aaaaaa"
                    }

                }
            ]
            if(!res.data.data.enterservice) res.data.data.enterservice = [];
            res.data.data.pic = res.data.data.pic.split('|')
            this.setData({
                detailInfo: res.data.data,
                llItude: llItude,
                mapMks:mapMks
            })
            let self = this;
            wx.createSelectorQuery().select('.lf-detail-synopsis').boundingClientRect(function (rect) {
                let height = rect.height
                console.log(rect.height)
                self.setData({
                    showFlag: height < 110 ? false : true
                })
            }).exec()
        })
    },
    setCoordinates(itude,i){
        return itude.split(",")[i]
    }
})